<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>spring boot+selenium爬取数据 | 知识库</title>
    <meta name="generator" content="VuePress 1.9.2">
    <link rel="icon" href="/vuepress-theme-vdoing-doc/img/favicon.ico">
    <noscript><meta http-equiv="refresh" content="0; url=https://www.youngkbt.cn/noscript/"><style>.theme-vdoing-content { display:none }</noscript>
    <meta name="description" content="一个基于VuePress的 知识管理">
    <meta name="keywords" content="vuepress,theme,blog,vdoing">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/vuepress-theme-vdoing-doc/assets/css/0.styles.b0974950.css" as="style"><link rel="preload" href="/vuepress-theme-vdoing-doc/assets/js/app.f061d58b.js" as="script"><link rel="preload" href="/vuepress-theme-vdoing-doc/assets/js/2.9bf30e88.js" as="script"><link rel="preload" href="/vuepress-theme-vdoing-doc/assets/js/6.c97c5dc9.js" as="script"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/10.d2937c56.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/11.67567365.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/12.74e8c324.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/13.2376fcd7.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/14.57ef5c33.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/15.44e7c0ba.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/16.c2fb4c44.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/17.af212389.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/18.1e6acac7.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/19.54653ac9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/20.920cc499.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/21.37128fe3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/22.8f68a2f2.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/23.7b9f1ba6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/24.12adc291.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/25.cfe381e5.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/26.9cf879f6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/27.4e6190ea.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/28.1e22fc79.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/29.c57e047d.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/3.cdcce428.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/30.21a95474.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/31.ce97e6e3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/32.cdb45d73.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/33.fd95e780.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/34.cd49a408.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/35.fe128161.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/36.02043ece.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/37.02eee249.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/38.4650dec6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/39.04fb7652.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/4.c02b1e5f.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/40.7b51f807.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/41.1df513a9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/42.92a82cec.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/43.363fceef.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/44.867b24fd.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/45.89f64bfa.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/46.3a4c53d8.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/47.b8a31c80.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/48.7a584b38.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/49.98345029.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/5.cb45b2c7.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/50.6a0b68f4.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/51.8945cdf6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/52.6583e327.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/53.f6987dfc.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/54.cca012f3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/55.8c58cf5c.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/56.23e08364.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/57.08b54de0.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/58.131ee23e.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/59.45637607.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/60.fe9c5dd1.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/61.39ad8fda.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/62.ede47d34.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/63.4bb3e179.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/64.23f955bc.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/65.77ffc240.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/66.a4503c94.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/67.bd3d6fa6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/68.a003ac59.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/69.64c66f41.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/7.1e88af32.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/70.87dfbf7d.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/71.02806218.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/72.54e30335.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/73.002db3b4.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/74.e577570e.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/75.e610b3c9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/76.f684a067.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/77.8be17062.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/78.cabc6873.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/79.83febd7c.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/8.91701106.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/80.19e3b7ca.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/81.1b4cafb3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/82.752ef803.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/83.460cd49b.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/84.377a221f.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/85.016eaf98.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/86.604c5deb.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/87.d3a3662d.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/88.0cf7f581.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/89.40b002bd.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/9.94309dfb.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/90.086847f8.js">
    <link rel="stylesheet" href="/vuepress-theme-vdoing-doc/assets/css/0.styles.b0974950.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vuepress-theme-vdoing-doc/" class="home-link router-link-active"><img src="/vuepress-theme-vdoing-doc/img/logo.png" alt="知识库" class="logo"> <span class="site-name can-hide">知识库</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/vuepress-theme-vdoing-doc/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/52d5c3/" class="nav-link">主题初衷与诞生</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="nav-link">介绍</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e08c97/" class="nav-link">模板集</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="案例" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="link-title">案例</a> <span class="title" style="display:none;">案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="nav-link">01.后端.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/4bd4c3/" class="nav-link">02.前端.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Docker" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="link-title">Docker</a> <span class="title" style="display:none;">Docker</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="nav-link">Docker安装与卸载</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ceaf16/" class="nav-link">Docker常用命令</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Linux" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/489582/" class="link-title">Linux</a> <span class="title" style="display:none;">Linux</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/489582/" class="nav-link">01.防火墙设置.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/6babae/" class="nav-link">02.Linux文件压缩和解压要点.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ccdc52/" class="nav-link">03.Linux 文件目录管理.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="nav-link">04.Linux 文件内容查看编辑.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e7b850/" class="nav-link">05.Linux 网络管理.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="空间聚合" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="link-title">空间聚合</a> <span class="title" style="display:none;">空间聚合</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="nav-link">OGC标准函数</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/fcb182/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>MyBatis</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/01e8a8/" class="nav-link">01.XML 映射器.md</a></li></ul></li><li class="dropdown-item"><h4>国产数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3c4d09/" class="nav-link">01.达梦适配.md</a></li><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="nav-link">02.瀚高适配.md</a></li></ul></li><li class="dropdown-item"><h4>Selenium爬取数据</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/e110c2/" aria-current="page" class="nav-link router-link-exact-active router-link-active">spring boot+selenium爬取数据.md</a></li></ul></li></ul></div></div> <a href="https://gitee.com/" target="_blank" rel="noopener noreferrer" class="repo-link">
    Source
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/vuepress-theme-vdoing-doc/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/52d5c3/" class="nav-link">主题初衷与诞生</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="nav-link">介绍</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e08c97/" class="nav-link">模板集</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="案例" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="link-title">案例</a> <span class="title" style="display:none;">案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="nav-link">01.后端.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/4bd4c3/" class="nav-link">02.前端.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Docker" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="link-title">Docker</a> <span class="title" style="display:none;">Docker</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="nav-link">Docker安装与卸载</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ceaf16/" class="nav-link">Docker常用命令</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Linux" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/489582/" class="link-title">Linux</a> <span class="title" style="display:none;">Linux</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/489582/" class="nav-link">01.防火墙设置.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/6babae/" class="nav-link">02.Linux文件压缩和解压要点.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ccdc52/" class="nav-link">03.Linux 文件目录管理.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="nav-link">04.Linux 文件内容查看编辑.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e7b850/" class="nav-link">05.Linux 网络管理.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="空间聚合" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="link-title">空间聚合</a> <span class="title" style="display:none;">空间聚合</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="nav-link">OGC标准函数</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/fcb182/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>MyBatis</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/01e8a8/" class="nav-link">01.XML 映射器.md</a></li></ul></li><li class="dropdown-item"><h4>国产数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3c4d09/" class="nav-link">01.达梦适配.md</a></li><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="nav-link">02.瀚高适配.md</a></li></ul></li><li class="dropdown-item"><h4>Selenium爬取数据</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/e110c2/" aria-current="page" class="nav-link router-link-exact-active router-link-active">spring boot+selenium爬取数据.md</a></li></ul></li></ul></div></div> <a href="https://gitee.com/" target="_blank" rel="noopener noreferrer" class="repo-link">
    Source
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <div class="sidebar-slot sidebar-slot-top">
  <a href="http://apifox.cn/a103xugaoyi" target="_blank">
<!--    <img src="https://cdn.staticaly.com/gh/xugaoyi/blog-gitalk-comment@master/img/431669861564_.2470ykdcpbds.jpg" alt="npm" class="no-zoom" style="width: 100%;border-radius: 2px;">-->
<!--    <p style="text-align: center;margin: 0;color: #999;font-size: 12px;">(进入注册为作者充电)</p>-->
  </a></div> <ul class="sidebar-links"><li><a href="/vuepress-theme-vdoing-doc/pages/c9d188/" class="sidebar-link">链接分析</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>MyBatis</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vuepress-theme-vdoing-doc/pages/01e8a8/" class="sidebar-link">XML 映射器</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>国产数据库</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vuepress-theme-vdoing-doc/pages/3c4d09/" class="sidebar-link">PLUS达梦适配</a></li><li><a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="sidebar-link">PLUS瀚高适配</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Selenium爬取数据</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vuepress-theme-vdoing-doc/pages/e110c2/" aria-current="page" class="active sidebar-link">spring boot+selenium爬取数据</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/vuepress-theme-vdoing-doc/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>后端</span></li><li data-v-06225672><span data-v-06225672>Selenium爬取数据</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://gitee.com/wenlongjia" target="_blank" title="作者" class="beLink" data-v-06225672>Insist</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-04-11</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">spring boot+selenium爬取数据<!----></h1> <div class="page-slot page-slot-top">
    <div class="wwads-cn wwads-horizontal page-wwads" data-id="136"></div>
    <style>
      .page-wwads{
        width:100%!important;
        min-height: 0;
        margin: 0;
      }
      .page-wwads .wwads-img img{
        width:80px!important;
      }
      .page-wwads .wwads-poweredby{
        width: 40px;
        position: absolute;
        right: 25px;
        bottom: 3px;
      }
      .wwads-content .wwads-text, .page-wwads .wwads-text{
        height: 100%;
        padding-top: 5px;
        display: block;
      }
  </style>
  </div> <div class="theme-vdoing-content content__default"><div class="language-java extra-class"><pre class="language-java"><code>     <span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span> selenium<span class="token operator">-</span>java <span class="token operator">--</span><span class="token operator">&gt;</span>
    <span class="token generics"><span class="token punctuation">&lt;</span>dependency<span class="token punctuation">&gt;</span></span>
       <span class="token generics"><span class="token punctuation">&lt;</span>groupId<span class="token punctuation">&gt;</span></span>org<span class="token punctuation">.</span>seleniumhq<span class="token punctuation">.</span>selenium<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
       <span class="token generics"><span class="token punctuation">&lt;</span>artifactId<span class="token punctuation">&gt;</span></span>selenium<span class="token operator">-</span>java<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
       <span class="token generics"><span class="token punctuation">&lt;</span>version<span class="token punctuation">&gt;</span></span>$<span class="token punctuation">{</span>selenium<span class="token punctuation">.</span>version<span class="token punctuation">}</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h3 id="简介"><a href="#简介" class="header-anchor">#</a> 简介</h3> <p><code>selenium-java 是 selenium的java 版，根据不一样driver，能够驱动不一样的浏览区，好比 selenium-chrome-driver、selenium-edge-driver、selenium-firefox-driver、selenium-ie-driver、selenium-opera-driver、phantomjsdriver等等，我用了其中的chromedriver 和 phantomjsdriver，这个能彻底模拟真实用户操做，不错的测试框架。</code></p> <h3 id="各浏览器下载地址"><a href="#各浏览器下载地址" class="header-anchor">#</a> 各浏览器下载地址：</h3> <div class="language-text extra-class"><pre class="language-text"><code>Firefox浏览器驱动：geckodriver
Chrome浏览器驱动：chromedriver | taobao备用地址
http://chromedriver.storage.googleapis.com/index.html
https://registry.npmmirror.com/binary.html?path=chromedriver/
IE浏览器驱动：IEDriverServer
Edge浏览器驱动：MicrosoftWebDriver
Opera浏览器驱动：operadriver
PhantomJS浏览器驱动：phantomjs
</code></pre></div><h3 id="浏览器驱动"><a href="#浏览器驱动" class="header-anchor">#</a> 浏览器驱动</h3> <div class="language- extra-class"><pre class="language-text"><code>WebDriver driver = new ChromeDriver();//Chrome浏览器
 
WebDriver driver = new FirefoxDriver();//Firefox浏览器
 
WebDriver driver = new EdgeDriver();//Edge浏览器
 
WebDriver driver = new InternetExplorerDriver();//IE浏览器
 
WebDriver driver = new OperaDriver();//Opera浏览器

</code></pre></div><h3 id="元素定位"><a href="#元素定位" class="header-anchor">#</a> 元素定位</h3> <ol><li>8 种定位方法：id、name、class name、 tag name 、link text 、partial link text 、xpath、 css selector。对应方法如下：</li></ol> <div class="language- extra-class"><pre class="language-text"><code>findElement(By.id());
findElement(By.name());
findElement(By.className());
findElement(By.tagName());
findElement(By.linkText());
findElement(By.partialLinkText());
findElement(By.xpath());
findElement(By.cssSelector());
</code></pre></div><p><img src="/vuepress-theme-vdoing-doc/assets/img/img_3.789b8931.png" alt="img_3.png">
2. 控制浏览器操作</p> <ul><li>控制浏览器窗口大小</li></ul> <div class="language- extra-class"><pre class="language-text"><code>maximize() 设置浏览器最大化
setSize() 设置浏览器宽高
driver.manage().window().maximize();
driver.manage().window().setSize(new Dimension(450, 600));
</code></pre></div><ul><li>控制浏览器后退、前进</li></ul> <div class="language- extra-class"><pre class="language-text"><code>back() 模拟浏览器后退按钮
forward() 模拟浏览器前进按钮
//后退
driver.navigate().back();
//前进
driver.navigate().forward();
</code></pre></div><ul><li>刷新页面 refresh()</li></ul> <div class="language- extra-class"><pre class="language-text"><code>driver.navigate().refresh();
</code></pre></div><ol start="3"><li>常用方法</li></ol> <div class="language- extra-class"><pre class="language-text"><code>clear() 清除文本。

sendKeys(*value) 模拟按键输入

click() 单击元素

submit()提交表单

getSize() 返回元素的尺寸

getText() 获取元素的文本

getAttribute(name) 获得属性值

isDisplayed() 设置该元素是否用户可见

close() 关闭当前窗口，如果它是当前打开的最后一个窗口，则退出浏览器

quit() 退出此驱动程序，关闭所有相关窗口
</code></pre></div><ol start="4"><li>鼠标操作</li></ol> <div class="language- extra-class"><pre class="language-text"><code>contextClick() 右击

clickAndHold() 鼠标点击并控制

doubleClick() 双击

dragAndDrop() 拖动

release() 释放鼠标

perform() 执行所有Actions中存储的行为
</code></pre></div><div class="language- extra-class"><pre class="language-text"><code>//双击“百度一下”
Actions action = new Actions(driver);
action.doubleClick(driver.findElement(By.id(&quot;su&quot;))).perform();
</code></pre></div><ol start="5"><li>键盘操作</li></ol> <div class="language- extra-class"><pre class="language-text"><code>常用键盘操作全选、回车、删除、cv等等，对应操作有：

sendKeys(Keys.BACK_SPACE) 回格键（BackSpace）
sendKeys(Keys.SPACE) 空格键(Space)
sendKeys(Keys.TAB) 制表键(Tab)
sendKeys(Keys.ESCAPE) 回退键（Esc）
sendKeys(Keys.ENTER) 回车键（Enter）
sendKeys(Keys.CONTROL,‘a’) 全选（Ctrl+A）
sendKeys(Keys.CONTROL,‘c’) 复制（Ctrl+C）
sendKeys(Keys.CONTROL,‘x’) 剪切（Ctrl+X）
sendKeys(Keys.CONTROL,‘v’) 粘贴（Ctrl+V）
sendKeys(Keys.F1) 键盘 F1

//eg：删除键使用
WebDriver driver = new ChromeDriver();
driver.get(&quot;https://www.baidu.com&quot;);
WebElement input = driver.findElement(By.id(&quot;kw&quot;));
input.sendKeys(&quot;hello&quot;);
input.sendKeys(Keys.BACK_SPACE);

</code></pre></div><ol start="6"><li>定位一组元素</li></ol> <div class="language- extra-class"><pre class="language-text"><code>针对第二部分描述，只需要在原来加一个s就可以获取一个List列表
findElements(By.id())
findElements(By.name())
findElements(By.className())
findElements(By.tagName())
findElements(By.linkText())
findElements(By.partialLinkText())
findElements(By.xpath())
findElements(By.cssSelector())
</code></pre></div><ol start="7"><li>表单和窗口切换</li></ol> <div class="language- extra-class"><pre class="language-text"><code>1).表单切换。frame/iframe 表单嵌套页面需要通过 switchTo().frame()方法切换，frame()里传递的参数为定位frame的WebElement。

2).窗口切换。需要获取窗口权柄然后切换页面。
</code></pre></div><ol start="8"><li>下拉框选择</li></ol> <div class="language- extra-class"><pre class="language-text"><code>Select类处理下拉框

//eg：获取下拉框元素，实例化Select类，然后通过selectByValue选择
WebElement element = driver.findElement(By.id(&quot;//select&quot;));
Select sel = new Select(element);
sel.selectByValue(&quot;10&quot;);
</code></pre></div><ol start="9"><li>警告框/alert处理</li></ol> <div class="language- extra-class"><pre class="language-text"><code>getText()： 返回 alert/confirm/prompt 中的文字信息。

accept()： 接受警告框。

dismiss()： 解散警告框。

sendKeys(keysToSend)： 发送文本至警告框。

keysToSend： 将文本发送至警告框。

//eg:接受警告框。
driver.switchTo().alert().accept();
</code></pre></div><ol start="10"><li>截图/滚动截图</li></ol> <p><code>Selenium提供了一种功能，称为TakeScreenShot界面，可用于拍摄可视区域的屏幕截图，该接口提供getScreenshotAs的方法，可捕获屏幕截图并将其存储在所需的位置</code></p> <div class="language- extra-class"><pre class="language-text"><code>//eg:截图
File srcfile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileInputStream fileInputStream = new FileInputStream(srcfile);

//eg:滚动截图
PageSnapshot pageSnapshot = Shutterbug.shootPage(driver, Capture.FULL);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(pageSnapshot.getBytes());
</code></pre></div><ol start="11"><li>浏览器cookies</li></ol> <div class="language- extra-class"><pre class="language-text"><code>getCookies() 获得所有 cookie 信息。

getCookieNamed(String name) 返回字典的key为“name”的Cookie信息。

addCookie(cookie dict) 添加Cookie。“cookie_dict”指字典对象，必须有 name和value值。

deleteCookieNamed(String name) 删除Cookie 信息。 “name”是要删除的 cookie的名称； “optionsString” 是该Cookie的选项，目前支持的选项包括“路径” ， “域” 。

deleteAllCookies() 删除所有 cookie 信息。

//eg
WebDriver driver = new ChromeDriver();
driver.get(&quot;https://www.baidu.com&quot;);
Cookie cookie1 = new Cookie(&quot;name&quot;, &quot;cookieName&quot;);
Cookie cookie2 = new Cookie(&quot;value&quot;, &quot;cookieValue&quot;);
driver.manage().addCookie(c1);
driver.manage().addCookie(c2);
//获取 cookie
Set&lt;Cookie&gt; cookie = driver.manage().getCookies();
//删除所有 cookie
driver.manage().deleteAllCookies();
</code></pre></div><ol start="12"><li>调用JavaScript
<code>WebDriver提供了executeScript()方法来执行JavaScript代码</code></li></ol> <div class="language- extra-class"><pre class="language-text"><code>//eg:
//实例化JavascriptExecutor
JavascriptExecutor driver_js = ((JavascriptExecutor) driver);
//编写js
String js=&quot;window.location.href = 'https://www.baidu.com/';&quot;;
//执行js代码
driver_js.executeScript(js);
</code></pre></div><h3 id="代码实例"><a href="#代码实例" class="header-anchor">#</a> 代码实例</h3> <div class="language-java extra-class"><pre class="language-java"><code>        <span class="token class-name">ChromeOptions</span> options <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ChromeOptions</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 设置容许弹框</span>
        options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;disable-infobars&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;disable-web-security&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 设置无gui 开发时仍是不要加，能够看到浏览器效果</span>
        options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;--headless&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> driverPath <span class="token operator">=</span>  <span class="token string">&quot;C:\\Users\\Administrator\\Desktop\\chromedriver\\chromedriver.exe&quot;</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span><span class="token function">setProperty</span><span class="token punctuation">(</span><span class="token string">&quot;webdriver.chrome.driver&quot;</span><span class="token punctuation">,</span> driverPath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">RemoteWebDriver</span> driver<span class="token operator">=</span>  <span class="token keyword">new</span> <span class="token class-name">ChromeDriver</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span><span class="token punctuation">;</span>
        driver<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;https://item.jd.com/100033901461.html&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="注意linux部署"><a href="#注意linux部署" class="header-anchor">#</a> 注意LINUX部署</h3> <div class="language- extra-class"><pre class="language-text"><code>yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
rpm -i google-chrome-stable_current_x86_64.rpm

google-chrome -version

//下载驱动赋权限
chmod a+x chromedriver

cd /usr/sbin

google-chrome
</code></pre></div><p><img src="/vuepress-theme-vdoing-doc/assets/img/img.8c4df87d.png" alt="img_3.png"></p> <div class="language-java extra-class"><pre class="language-java"><code>    <span class="token comment">// 设置容许弹框</span>
    options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;disable-infobars&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;disable-web-security&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 设置无gui 开发时仍是不要加，能够看到浏览器效果</span>
    options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;--headless&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;--no-sandbox&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;--disable-gpu&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    options<span class="token punctuation">.</span><span class="token function">addArguments</span><span class="token punctuation">(</span><span class="token string">&quot;--disable-dev-shm-usage&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div></div></div>  <div class="page-edit"><!----> <!----> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">PLUS瀚高适配</div></a> <!----></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="prev">PLUS瀚高适配</a></span> <!----></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2024
    <span>Insist | MIT License</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/vuepress-theme-vdoing-doc/assets/js/app.f061d58b.js" defer></script><script src="/vuepress-theme-vdoing-doc/assets/js/2.9bf30e88.js" defer></script><script src="/vuepress-theme-vdoing-doc/assets/js/6.c97c5dc9.js" defer></script>
  </body>
</html>
